package com.example.flower_shop.dto.address;

import com.example.flower_shop.entity.Address;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

@Data
@NoArgsConstructor
public class AddressDTO {
    private Long id;

    @NotBlank(message = "收货人姓名不能为空")
    private String receiverName;

    @NotBlank(message = "手机号不能为空")
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
    private String receiverPhone;

    @NotBlank(message = "省份不能为空")
    private String province;

    @NotBlank(message = "城市不能为空")
    private String city;

    @NotBlank(message = "区县不能为空")
    private String district;

    @NotBlank(message = "详细地址不能为空")
    private String detailAddress;

    private Boolean isDefault = false;

    public AddressDTO(Address address) {
        this.id = address.getId();
        this.receiverName = address.getReceiverName();
        this.receiverPhone = address.getReceiverPhone();
        this.province = address.getProvince();
        this.city = address.getCity();
        this.district = address.getDistrict();
        this.detailAddress = address.getDetailAddress();
        this.isDefault = address.getIsDefault();
    }
}